package com.zx.flow.db.typehandler;

import com.zx.flow.api.dict.FlowDict.Status;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

/**
 *
 */
public class FlowStatusTypeHandler extends BaseTypeHandler<Status> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Status e, JdbcType jdbcType)
            throws SQLException {
        preparedStatement.setString(i, e.getCode());
    }

    @Override
    public Status getNullableResult(ResultSet resultSet, String s) throws SQLException {
        String code = resultSet.getString(s);
        return resultSet.wasNull() ? null : Status.getByCode(code);
    }

    @Override
    public Status getNullableResult(ResultSet resultSet, int i) throws SQLException {
        String code = resultSet.getString(i);
        return resultSet.wasNull() ? null : Status.getByCode(code);
    }

    @Override
    public Status getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        String code = callableStatement.getString(i);
        return callableStatement.wasNull() ? null : Status.getByCode(code);
    }
}